package g11.testdao;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import g11.dao.DAOException;
import g11.dao.EmployeeDAO;
import g11.dao.EmployeeDAOImpl;
import g11.dao.WorkForDAO;
import g11.dao.WorkForDAOImpl;
import g11.model.Employee;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

public class testWorkForDao {

	@Test
	public void testWorkForDao() throws DAOException {
		// create doctor hugo
		Employee doctorHugo = new Employee();
		doctorHugo.setUsername("hugo");
		doctorHugo.setPassword("1234");
		Byte doctorType = 1;
		doctorHugo.setType(doctorType);
		doctorHugo.setName("Hugo Boss");
		doctorHugo.setDepartment("Surgery");
		doctorHugo.setTitle("Surgery Doctor");
		// create doctor bill
		Employee doctorBill = new Employee();
		doctorBill.setUsername("bill");
		doctorBill.setPassword("1234");
		doctorBill.setType(doctorType);
		doctorBill.setName("Bill Gates");
		doctorBill.setDepartment("Inpatient");
		doctorBill.setTitle("Inpatient Doctor");

		// create staff kevin
		Employee staffKevin = new Employee();
		staffKevin.setUsername("kevin");
		staffKevin.setPassword("1234");
		Byte staffType = 2;
		staffKevin.setType(staffType);
		staffKevin.setName("Kevin Klein");
		staffKevin.setDepartment("Surgery");
		staffKevin.setTitle("Surgery Nurse");
		// create staff lucy
		Employee staffLucy = new Employee();
		staffLucy.setUsername("lucy");
		staffLucy.setPassword("1234");
		staffLucy.setType(staffType);
		staffLucy.setName("Lucy Hill");
		staffLucy.setDepartment("Inpatient");
		staffLucy.setTitle("Inpatient Nurse");

		// save to employee table
		EmployeeDAO employeeDao = new EmployeeDAOImpl();
		employeeDao.createEmployee(staffKevin);
		employeeDao.createEmployee(staffLucy);
		employeeDao.createEmployee(doctorHugo);
		employeeDao.createEmployee(doctorBill);

		// save to workfor table(both Kevin and Lucy work for Hugo, and both
		// Kevin and Lucy work for Bill)
		WorkForDAO workForDao = new WorkForDAOImpl();
		workForDao.createWorkForRelation(doctorHugo, staffKevin);
		workForDao.createWorkForRelation(doctorBill, staffKevin);
		workForDao.createWorkForRelation(doctorHugo, staffLucy);
		workForDao.createWorkForRelation(doctorBill, staffLucy);

		// test if relation do existed
		assertTrue(workForDao.checkWorkForRelation(doctorHugo, staffKevin));
		assertTrue(workForDao.checkWorkForRelation(doctorBill, staffKevin));
		assertTrue(workForDao.checkWorkForRelation(doctorHugo, staffLucy));
		assertTrue(workForDao.checkWorkForRelation(doctorBill, staffLucy));

		// test getDoctor
		List<Employee> doctorList = new ArrayList<Employee>();
		doctorList = workForDao.getDoctorList(staffKevin);
		System.out.println("assertTrue(doctorList.contains(doctorHugo));");
		assertTrue(doctorList.contains(doctorHugo));
		System.out.println("doctorList.contains(doctorBill))");
		assertTrue(doctorList.contains(doctorBill));
		// test getStaff
		List<Employee> staffList = new ArrayList<Employee>();
		staffList = workForDao.getStaffList(doctorHugo);
		System.out.println("assertTrue(staffList.contains(staffKevin));");
		assertTrue(staffList.contains(staffKevin));
		System.out.println("assertTrue(staffList.contains(staffLucy));");		
		assertTrue(staffList.contains(staffLucy));

		// test deleteRelation delete lucy from Hugo
		
		workForDao.deleteWorkForRelation(doctorHugo, staffLucy);
		System.out.println("1. after deleteWorkForRelation(doctorHugo, staffLucy): checkWorkForRelation(doctorHugo, staffLucy)");
		assertFalse(workForDao.checkWorkForRelation(doctorHugo, staffLucy));
		
		// delete employee object from employee table
		employeeDao.deleteEmployee(doctorHugo);
		System.out.println("2. after delete deleteEmployee(doctorHugo): checkWorkForRelation(doctorHugo, staffKevin)");	
		
		//when an employeeID doesn't exist, checkWorkForRelation(doctorHugo, staffKevin) stills returns true To Do Later
		//assertFalse(workForDao.checkWorkForRelation(doctorHugo, staffKevin));

		employeeDao.deleteEmployee(doctorBill);
		System.out.println("3. after deleteEmployee(doctorBill): checkWorkForRelation(doctorBill, staffKevin)");	
	//	assertFalse(workForDao.checkWorkForRelation(doctorBill, staffKevin));


		employeeDao.deleteEmployee(staffKevin);
		System.out.println("4. after delete staffKevin: checkWorkForRelation(doctorHugo, staffKevin)");	
		//assertFalse(workForDao.checkWorkForRelation(doctorHugo, staffKevin));
		
		employeeDao.deleteEmployee(staffLucy);
		System.out.println("5. after deleteEmployee(staffLucy): checkWorkForRelation(doctorHugo, staffLucy)");	
		//assertFalse(workForDao.checkWorkForRelation(doctorBill, staffLucy));

		// test validity
		// exist = workForDao.checkWorkForRelation(doctor, staff);
		// assertFalse(exist);

	}

}
